<?php
/**
 * 商品类别模型
 *
 *
 *
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */

defined('InShopNC') or exit('Access Invalid!');

class channelsModel extends Model
{
    /**
     * 缓存数据
     */
    protected $cachedData;

    /**
     * 缓存数据 原H('goods_class')形式
     */
    protected $gcForCacheModel;

    public function __construct() {
        parent::__construct('channels');
    }

    /**
     * 删除缓存数据
     */
    public function dropCache() {
        $this->cachedData = null;
        $this->gcForCacheModel = null;

        dkcache('gc_class');
        dkcache('all_categories');
    }

    public function getChannelsList($condition, $field = '*', $group = '',$order = '', $limit = 0, $page = 0, $lock = false, $count = 0) {
        return $this->table('channels')->field($field)->where($condition)->group($group)->order($order)->limit($limit)->page($page, $count)->lock($lock)->select();
    }
    /**
     * 从缓存获取分类 通过分类id
     *
     * @param int $id 分类id
     */
    public function getChannelsInfoById($id) {
        $condition = array('channels_id'=>$id);
        return $this->table('channels')->field($field)->where($condition)->find();
    }



    /**
     * 更新信息
     * @param unknown $data
     * @param unknown $condition
     */
    public function editChannels($data = array(), $condition = array()) {
        // 删除缓存
        $this->dropCache();
        return $this->where($condition)->update($data);
    }

    /**
     * 删除商品分类
     * @param unknown $condition
     * @return boolean
     */
    public function delGoodsClass($condition) {
        // 删除缓存
        $this->dropCache();
        return $this->where($condition)->delete();
    }

    /**
     * 新增商品分类
     * @param array $insert
     * @return boolean
     */
    public function addChannels($insert) {
        // 删除缓存
        $this->dropCache();
        return $this->insert($insert);
    }
}
